﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows;
using System.Windows.Shapes;

namespace Shrestha.Trigraph
{
    class LegendMarker: Shape
    {
        private Brush fillColor;

        public double MarkerHeight, MarkerWidth, X, Y;

        public LegendMarker(double xcoordinate, double ycoordinate, double height, double width, Brush b)
        {
            X = xcoordinate; Y = ycoordinate; MarkerHeight = height; MarkerWidth = width;
            fillColor = b;
            this.Stroke = Brushes.Black;
            this.Fill = fillColor;
        }

        public LegendMarker() { }

        protected override Geometry DefiningGeometry
        {
            get
            {
                // Create a StreamGeometry for describing the shape
                StreamGeometry geometry = new StreamGeometry();
                geometry.FillRule = FillRule.EvenOdd;

                using (StreamGeometryContext context = geometry.Open())
                {
                    InternalTriMarkerGeometry(context);
                }

                // Freeze the geometry for performance benefits
                geometry.Freeze();

                return geometry;
            }
        }

        private void InternalTriMarkerGeometry(StreamGeometryContext context)
        {
            int mh = (int)(MarkerHeight / 2);
            int mw = (int)(MarkerWidth / 2);
            Point p1 = new Point(X-mw, Y-mh);
            Point p2 = new Point(X + mw, Y-mh);
            Point p3 = new Point(X + mw, Y + mh);
            Point p4 = new Point(X-mw, Y + mh);

            context.BeginFigure(p1, true, true);
            context.LineTo(p2, true, true);
            context.LineTo(p3, true, true);
            context.LineTo(p4, true, true);
        }

    }
}
